#include <stdio.h>
#include "portable_socket.h"
#include "encode.h"
#include "md4.h"
#include "md5.h"
#include "sha1.h"
#include <gtk/gtk.h>

int main( int   argc, char *argv[] )
{
	char buffer[1024];
/*

	char encoded[1024];
	buffer[0] = 0;

	md4_file_range(argv[1], buffer, (off_t)0, (off_t)0);
	base32_encode(encoded, 1024, buffer, 16);
	printf("MD4:  %s\n", encoded);

	md5_file_range(argv[1], buffer, (off_t)0, (off_t)0);
	base32_encode(encoded, 1024, buffer, 16);
	printf("MD5:  %s\n", encoded);

	sha1_file_range(argv[1], buffer, (off_t)0, (off_t)0);
	base32_encode(encoded, 1024, buffer, 20);
	printf("SHA1: %s\n", encoded);

	exit(0);*/
	psocket_init();


	if(argc == 1){
		struct st_psocket my_socket;
		printf("binding\n");
		psocket_bind(&my_socket, "0.0.0.0", 1025);
		printf("accepting\n");
		psocket_accept(&my_socket);
		create_server_key("incorp.pem", 512, 2, "US", "Incorp");
		psocket_set_openssl(&my_socket, "incorp.pem");
		psocket_readline_r(&my_socket, buffer, 1024);
		printf("buffer: %s\n", buffer);
	}
	else{
		struct st_psocket my_socket;
		my_socket.io_method = IO_OPENSSL;
		printf("connecting\n");
		if(psocket_connect(&my_socket, "127.0.0.1", 1025) == 0){
			printf("connected\n");
			psocket_fullsend(&my_socket, "HELLO karlan\nhow\nkaarl", strlen("HELLO karlan\nhow\nkaarl"));
			}
	}
	exit(0);
	}